package com.fan.beanutils;

import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;


public class Servlet5 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doGet(request, response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("UTF-8");
         //1.获取所有的请求参数
        Map<String, String[]> parameterMap = request.getParameterMap();
        //2.将请求参数封装到User对象中
        User user = new User();
        //3.使用BeanUtils框架自动将map中的数据封装到对象中
        try {
            BeanUtils.populate(user,parameterMap);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
